import com.itheima.domain.Book;
import com.ithema.comfig.SpringConfig;
import com.ithema.service.BookService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class test {
    @Autowired
    private BookService bookService;

    @Test
    public void selectBook(){
        Book book = bookService.selectBook_Id(15);
        System.out.println(book);
    }

    @Test
    public void selectBook_All(){
        List<Book> books = bookService.selectBookAll();
        System.out.println(books);
    }

    @Test
    public void save_Book(){
        Book book = new Book();
        book.setId(null);
        book.setType("12312313从入行到跑行");
        book.setName("跟史哥学java");
        book.setDescription("带你飞出天际");
        boolean b = bookService.saveBook(book);
        if (b==true){
            System.out.println("添加成功");
        }
    }

    @Test
    public void delete_Book(){
        boolean b = bookService.deleteBook(5);
        if (b==true){
            System.out.println("删除成功");
        }
    }

    @Test
    public void update_Book(){
        Book book = new Book();
        book.setId(1);
        book.setType("12312313从入行到跑行");
        book.setName("跟史哥学java");
        book.setDescription("带你飞出天际");
        boolean b = bookService.update(book);
        if (b==true){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");

        }
    }
}
